package com.powernode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.powernode.constant.ProductConstants;
import com.powernode.domain.ProdTag;
import com.powernode.mapper.ProdTagMapper;
import com.powernode.service.ProdTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Service
@CacheConfig(cacheNames = "com.powernode.service.impl.ProdTagServiceImpl")
public class ProdTagServiceImpl extends ServiceImpl<ProdTagMapper, ProdTag> implements ProdTagService {
    @Autowired
    private ProdTagMapper prodTagMapper;
    /*
     * 新增分组标签
     * @author RenBoQing
     * @date 2024/7/27 19:05
     * @param productTag
     * @return boolean
     */
    @Override
    @CacheEvict(key = ProductConstants.PROD_TAG_NORMAL_KEY)
    public boolean saveProTag(ProdTag productTag) {
        productTag.setCreateTime(new Date());
        productTag.setUpdateTime(new Date());
        return prodTagMapper.insert(productTag)>0;
    }
    /*
     * 修改分组标签
     * @author RenBoQing
     * @date 2024/7/27 19:59
     * @param productTag
     * @return boolean
     */
    @Override
    @CacheEvict(key = ProductConstants.PROD_TAG_NORMAL_KEY)
    public boolean updateProTag(ProdTag productTag) {
        productTag.setUpdateTime(new Date());
        return prodTagMapper.updateById(productTag) > 0;
    }

    /*
     *删除分组标签
     * @author RenBoQing
     * @date 2024/7/28 12:34
     * @param id
     * @return boolean
     */
    @Override
    @CacheEvict(key = ProductConstants.PROD_TAG_NORMAL_KEY)
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

    /*
     * 查询状态正常的商品分组标签集合
     * @author RenBoQing
     * @date 2024/7/28 12:24
     * @return java.util.List<com.powernode.domain.ProdTag>
     */
    @Override
    @Cacheable(key = ProductConstants.PROD_TAG_NORMAL_KEY)
    public List<ProdTag> queryProdTagList() {
        return prodTagMapper.selectList(new LambdaQueryWrapper<ProdTag>().eq(ProdTag::getStatus, 1).orderByDesc(ProdTag::getSeq));
    }
}